﻿using System;
using System.Web;
using EPiServer.Personalization.VisitorGroups;

namespace CriteriaPack.TimePeriodCriterion
{
    [VisitorGroupCriterion(DisplayName = "Time Period", Category = "Time and Place Criteria", LanguagePath = "/shell/cms/visitorgroups/criteria/timeperiod")]
    public class TimePeriodCriterion : CriterionBase<TimePeriodCriterionModel>
    {
        public override bool IsMatch(System.Security.Principal.IPrincipal principal, HttpContextBase httpContext)
        {
            return DateTime.Now >= this.RangeStart && DateTime.Now <= RangeEnd;
        }

        protected DateTime RangeStart
        {
            get
            {
                return Model.StartDate.Add(Model.StartTime.TimeOfDay);
            }
        }

        protected DateTime RangeEnd
        {
            get
            {
                return Model.EndDate.Add(Model.EndTime.TimeOfDay);
            }
        }
    }
}